<!DOCTYPE html>
<html>
<head>
	<title>Close (remove) tab</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<script>
		var myRibbon;
		var isBusy = false;
		var loadData = {};
		function doOnLoad() {
			if (!checkLoadState()) return;
			loadData = {ribbon: false};
			isBusy = false;
			myRibbon = new dhtmlXRibbon({
				parent: "ribbonObj",
				icons_path: "../common/"
			});
			myRibbon.attachEvent("onXLE", function(){
				loadData.ribbon = true;
			});
			myRibbon.loadStruct("../common/tabs.json");
		};

		function doOnUnload() {
			if (myRibbon) {
				myRibbon.unload();
				myRibbon = null;
			}
		};
		
		function _close(id,activateId) {
			if (isBusy) return;
			isBusy = true;
			if (myRibbon.tabs(id) != null) {
				myRibbon.tabs(id).close(activateId);
			}
		};
		function refresh() {
			window.onunload();
			window.onload();
		}
		function checkLoadState() {
			var s = true;
			for (var a in loadData) s = s&&loadData[a];
			return s;
		}
	</script>

</head>
<body onload="doOnLoad();" onunload="doOnUnload();">
	<div id="ribbonObj"></div>
	<div>Tab 1 <button onclick="_close('tab_1')">close and select next tab</button></div>
	<div>Tab 1 <button onclick="_close('tab_1',false)">close a1 and do not select any tab</button></div>
	<div>Tab 1 <button onclick="_close('tab_1','tab_3')">close end select tab 3</button></div>
	<button onclick="refresh()">Refresh</button>
</body>
</html>